from fastapi import APIRouter, logger
from .annotations import ID_PATH_PARAM
from models import Student
from schemas.all import StudentSchema, StudentListSchema

student_api = APIRouter(prefix='/student')

log = logger.logger

@student_api.get("", response_model=list[StudentListSchema])
async def get_students():
    students = await Student.all().prefetch_related('courses').prefetch_related('courses__teacher').select_related('clas')
    print(type(students))
    print(students)
    return students
    

@student_api.get("/{student_id}", response_model=StudentListSchema)
async def get_student(student_id: ID_PATH_PARAM):
    student = await Student.all().prefetch_related('courses').select_related('clas').get(id=student_id)
    print(student)
    return student


@student_api.post("", response_model=StudentSchema)
async def create_student(student: StudentSchema):
    log.info(f'student create: {student}')
    print(student)
    s = await student.create()
    print(s)
    return student


@student_api.put("/{student_id}")
def update_student(student_id: ID_PATH_PARAM):
    return {"student_id": student_id}


@student_api.delete("/{student_id}")
def delete_student(student_id: ID_PATH_PARAM):
    return {"student_id": student_id}

